// pages/member/userinfo/userinfo.js
import { PNT, setNavBarTitle, pushPagePath } from "../../../utils/utils";
import { GetuserReal } from "../../../utils/apis";
import { CheckUserLevel, CheckCartTotal } from "../../../utils/publics";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    touxiang:'',
    nicheng:  '东龙',
    name:'sssss',
    xb:'男',
    smrz:0,
   
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    setNavBarTitle(PNT.member.main);
    this.loginModal = this.selectComponent("#login-modal");
    if(!this.loginModal.check()){
      wx.navigateBack({
        delta:1,
      })
    }

  },
  tuichu: function (e) {
    console.log('dddd');
  },
  nichange:function(){
    wx.navigateTo({
      url: '/pages/member/userinfo/niname',
    })
  },
  xbchange: function () {
    wx.navigateTo({
      url: '/pages/member/userinfo/xb',
    })
  },
  dzchange: function () {
    wx.navigateTo({
      url: '/pages/member/address/list/list',
    })
  },
  zhchange: function () {
    wx.navigateTo({
      url: '/pages/member/setting/setting',
    })
  },
  fileImg: function () {
    var me = this;
    wx.chooseImage({
      count: 1,
      success: function (res) {
        console.log(res)
        me.setData({
          touxiang:res.tempFilePaths[0],
        })
        me.setData({ imgUrl: res.tempFilePaths })
        wx.uploadFile({
          url: 'https://www.donglongshangshi.com/wechatapi/index.php/wechatapi/index/updateUserPic', //仅为示例，非真实的接口地址
          filePath: res.tempFiles[0].path,
          name: 'file',
          formData: {
            path: 'data/images_user/',
            user_id:me.data.info.user_id,
          },
          success: function (res) {
            var data = JSON.parse(res.data);
            if(data.error_code == 10000){
              me.setData({
                touxiang:data.data,
              })
              var info = me.data.info;
              info.user_picture = data.data;
              wx.setStorageSync('userInfo', info);
            }else{
              wx.showToast({
                title: '修改失败',
                icon:"none"
              })
            }
            //do something
          }
        })
      }
    })
  },
rename(e){
  if(!this.data.smrz){
    wx.navigateTo({
      url: '/pages/member/realname/index',
    })
  }
},
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (!this.loginModal.check()) {
      wx.navigateBack({
        delta: 1,
      })
    }
    var info = wx.getStorageSync('userInfo');
    this.setData({
      info: info,
      touxiang: info.user_picture,
      nicheng: info.nick_name,
      xb: info.sex,
      // smrz: info.is_validated,
    })
    var data = {};
    data.user_id = info.user_id;
    GetuserReal(info.user_id).then(res=>{
      if(res.error_code == 10000){
        this.setData({
          smrz:1,
        })
      }else{
        this.setData({
          smrz: 0,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})